package com.db.bankapp.domain.bank;

/**
 * Created by Student on 18.08.2014.
 */
class CheckingAccount extends AccountBase {
    private int overdraft;

    public int getOverdraft() {
        return overdraft;
    }

    public CheckingAccount(int balance, int overdraft) {
        this.balance = balance;
        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(int amount) {
        assert balance >= 0 : "Balance! Balance<0!!";
        if (overdraft + balance < amount) {
            throw new IllegalArgumentException("Not enough money!");
        }
        if (balance >= amount) {
            balance -= amount;
        } else {
            overdraft = overdraft + balance - amount;
            balance = 0;
            System.out.println("Changing credit limit to " + overdraft);
        }
    }

    @Override
    public int maximumAmountToWithdraw() {
        return balance + overdraft;
    }
}
